'use strict'

const _ = require('lodash')
const moment = require('moment')
const Env = use('Env')
const { AliYunService } = require('../../Services')
const { FaExhibitor,FaProduct,UserExhibitor,ExhibitorReceipt,Exhibitor2021 } = require("../../Models");
class ExhibitorController {
  async index({request, response}) {
    let { page = 1, pageSize = 10 } = request.all()
    let list = await FaExhibitor.query().paginate(page, pageSize)
    response.json(list)
  }
  async show({request, response, params}) {
    console.log('params: ', params)
    
    let vo = await FaExhibitor.query().where('id',params.id).first()
    let c = await UserExhibitor.query().where('exhibitorID',params.id).getCount()
    vo.likeCount = c
    response.json(vo)
  }
  async exhibitor2021({request, response}) {
    let { page = 1, pageSize = 10, searchWord } = request.all()
    let list = null
    console.log(searchWord)
    if (searchWord) {
      searchWord = searchWord.trim()
      list = await Exhibitor2021.query()
                                    .where('hallRoomNo','like',`%${searchWord}%`)
                                    .orWhere('exhibitorName','like',`%${searchWord}%`)
                                    .orWhere('exhibitorNameEn','like',`%${searchWord}%`)
                                    .orWhere('cateName','like',`%${searchWord}%`)
                                    .paginate(page, pageSize)
    } else {
      list = await Exhibitor2021.query().paginate(page, pageSize)
    }
    
    response.json(list)
  }

}
module.exports = ExhibitorController